package com.flame.auth.core.entity;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 登录成功的用户信息
 *
 * @author wuxintong
 * @since 2022/12/28
 */
public class TrustedPrincipal implements Serializable {

    /** 用户账号(ID) */
    private String account;

    /** 机构编号(ID) */
    private String orgCode;

    /** 用户名称 */
    private String userName;

    /** 用户IP */
    private String ip;

    /** 用户角色编号列表 */
    private Set<String> roleList = new HashSet<>();

    /** 用户功能权限编号列表 */
    private Set<String> authList = new HashSet<>();

    /** 用户数据权限 Map，Key：数据类型，Value：权限范围 */
    @JsonIgnore
    private Map<String, String> dataAuthMap = new HashMap<>();

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getOrgCode() {
        return orgCode;
    }

    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public Set<String> getRoleList() {
        return roleList;
    }

    public void setRoleList(Set<String> roleList) {
        this.roleList = roleList;
    }

    public Set<String> getAuthList() {
        return authList;
    }

    public void setAuthList(Set<String> authList) {
        this.authList = authList;
    }

    public boolean hasRole(String role) {
        return roleList.contains(role);
    }

    public boolean hasAuth(String auth) {
        return authList.contains(auth);
    }

    public Map<String, String> getDataAuthMap() {
        return dataAuthMap;
    }

    public void setDataAuthMap(Map<String, String> dataAuthMap) {
        this.dataAuthMap = dataAuthMap;
    }
}
